home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tcqbsnip.zip / REPSTR.BAS < prev    next >
BASIC Source File  |  1997-06-20  |  898b  |  33 lines

  1. ' REPSTR.BAS
  2. ' by Tika Carr
  3. ' December 7, 1996
  4. '
  5. ' Donated to the Public Domain
  6. ' No warranties or guarantees are expressed or implied.
  7. '
  8. ' Purpose: Search for specific text in a string and replace it with something
  9. '          else. This routine is case sensitive.
  10.  
  11. DECLARE FUNCTION RepStr$ (A$, S$, R$)
  12.  
  13. CLS
  14. Original$ = "Hello, I'm Name. How are you?"   'Original String
  15. Target$ = "Name"                              'What we are going to replace
  16. Replace$ = "Somebody"                         'What we will replace it with
  17.  
  18. PRINT "Original: "; Original$
  19. PRINT "Search String: "; Target$
  20. PRINT "Replace with: "; Replace$
  21.  
  22. 'Call function to do work:
  23. PRINT "Modified: "; RepStr$(Original$, Target$, Replace$)
  24.  
  25. FUNCTION RepStr$ (A$, S$, R$)
  26.  
  27. T = INSTR(A$, S$)
  28. IF T > 0 THEN A$ = LEFT$(A$, T - 1) + R$ + RIGHT$(A$, LEN(A$) - T - LEN(S$) + 1)
  29. RepStr$ = A$
  30.  
  31. END FUNCTION
  32.  
  33.